// 语言数据 - 存储中英文翻译文本
const translations = {
    'zh': {
        'nav.home': '首页',
        'nav.about': '关于我',
        'nav.projects': '项目展示',
        'nav.contact': '联系我',
        'hero.title': '你好，我是<span class="highlight">设计师的名字</span>',
        'hero.subtitle': '专注于创造令人惊艳的设计作品',
        'hero.cta': '查看我的作品',
        'about.title': '关于我',
        'about.text1': '我是一位资深的Python Developer，专注于消息中间件、实时数据处理和高可用架构设计。我热衷于解决复杂的技术挑战，并不断探索新技术的应用。',
        'about.text2': '在工作之余，我对Rust编程语言有着浓厚的兴趣，也喜欢欣赏动画作品如《幸运星》、《孤独摇滚》和《摇曳露营》，这些爱好为我的技术工作带来了不同的视角和灵感。',
        'skills.title': '专业技能',
        'timeline.title': '专业经历',
        'timeline.degree1': '计算机科学与技术专业 本科',
        'timeline.degree2': '计算机科学专业 硕士',
        'timeline.job1': '软件工程师',
        'timeline.job2': '软件工程师',
        'achievements.title': '个人成就',
        'projects.title': '项目展示',
        'project1.title': '大数据开发',
        'project1.desc': '基于Python和Spark的大数据处理平台，实现了TB级数据的实时分析与可视化。',
        'project2.title': '计算机实操',
        'project2.desc': '交互式编程实验平台，提供多种编程语言的在线练习和实时反馈功能。',
        'project3.title': 'AI机器人研发',
        'project3.desc': '基于深度学习的智能机器人控制系统，支持计算机视觉和自然语言处理功能。',
        'contact.title': '联系我',
        'contact.email': '邮箱:',
        'contact.social': '社交媒体:',
        'form.name': '姓名',
        'form.email': '邮箱',
        'form.message': '留言',
        'form.submit': '发送',
        'footer.copyright': '© 2024 我的个人作品集. 保留所有权利.',
        'form.success': '消息已发送，感谢您的联系！',
        'form.error.name': '请输入您的姓名',
        'form.error.email': '请输入您的邮箱',
        'form.error.message': '请输入您的留言内容',
        'backToTop': '返回顶部'
    },
    'en': {
        'nav.home': 'Home',
        'nav.about': 'About',
        'nav.projects': 'Projects',
        'nav.contact': 'Contact',
        'hero.title': 'Hello, I am <span class="highlight">Designer Name</span>',
        'hero.subtitle': 'Focused on creating stunning design works',
        'hero.cta': 'View My Works',
        'about.title': 'About Me',
        'about.text1': 'I am a senior Python Developer specializing in message middleware, real-time data processing, and high-availability architecture design. I am passionate about solving complex technical challenges and constantly exploring new technology applications.',
        'about.text2': 'In my spare time, I have a strong interest in the Rust programming language and enjoy watching anime such as "Lucky Star", "Bocchi the Rock!", and "Laid-Back Camp". These hobbies bring different perspectives and inspiration to my technical work.',
        'skills.title': 'Professional Skills',
        'timeline.title': 'Professional Experience',
        'timeline.degree1': 'Bachelor of Computer Science and Technology',
        'timeline.degree2': 'Master of Computer Science',
        'timeline.job1': 'Software Engineer',
        'timeline.job2': 'Software Engineer',
        'achievements.title': 'Personal Achievements',
        'projects.title': 'Project Showcase',
        'project1.title': 'Big Data Development',
        'project1.desc': 'A big data processing platform based on Python and Spark, enabling real-time analysis and visualization of terabyte-scale data.',
        'project2.title': 'Computer Practice',
        'project2.desc': 'An interactive programming experiment platform offering online practice and real-time feedback for multiple programming languages.',
        'project3.title': 'AI Robot Research',
        'project3.desc': 'An intelligent robot control system based on deep learning, supporting computer vision and natural language processing capabilities.',
        'contact.title': 'Contact Me',
        'contact.email': 'Email:',
        'contact.social': 'Social Media:',
        'form.name': 'Name',
        'form.email': 'Email',
        'form.message': 'Message',
        'form.submit': 'Send',
        'footer.copyright': '© 2024 My Portfolio. All rights reserved.',
        'form.success': 'Message sent successfully, thank you for contacting!',
        'form.error.name': 'Please enter your name',
        'form.error.email': 'Please enter your email',
        'form.error.message': 'Please enter your message content',
        'backToTop': 'Back to Top'
    }
};

// 设置当前语言
let currentLang = localStorage.getItem('preferredLang') || 'zh';

// 初始化网站语言
document.addEventListener('DOMContentLoaded', function() {
    updateLanguage(currentLang);
});

// 更新网站语言
function updateLanguage(lang) {
    if (!translations[lang]) return;
    
    currentLang = lang;
    localStorage.setItem('preferredLang', lang);
    
    // 更新网站标题
    const siteTitle = lang === 'zh' ? '我的个人作品集' : 'My Portfolio';
    document.title = siteTitle;
    
    // 更新所有带有data-lang属性的元素
    document.querySelectorAll('[data-lang]').forEach(element => {
        const key = element.getAttribute('data-lang');
        if (translations[lang][key]) {
            if (element.tagName.toLowerCase() === 'input' || element.tagName.toLowerCase() === 'textarea') {
                element.setAttribute('placeholder', translations[lang][key]);
            } else {
                // 允许HTML内容
                element.innerHTML = translations[lang][key];
            }
        }
    });
    
    // 更新语言切换按钮状态
    document.querySelectorAll('.lang-switcher button').forEach(btn => {
        if (btn.dataset.lang === lang) {
            btn.classList.add('active');
        } else {
            btn.classList.remove('active');
        }
    });
}